/**
  ******************************************************************************
  * @file           : netwrok.h
  * @brief          : Header for g405tf.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __netwrok_H
#define __netwrok_H

#include "cat1.h"
#include "core_mqtt.h"
#include "cJSON.h"
#include "route.h"

#define ONEJSON_VERSION           "1.0"


#define NETWORK_SUBSCRIBE_BUFFER_MAXLEN      128

#define NETWORK_PUB_PAYLOAD_BUFFER_MAXLEN    1024
#define NETWORK_SUB_PAYLOAD_BUFFER_MAXLEN    1024

#define NETWORK_PUB_TOPIC_BUFFER_MAXLEN      128
#define NETWORK_SUB_TOPIC_BUFFER_MAXLEN      128


#define NETWORK_ACKS_QUE_LENGTH              5
#define NETWORK_ACKS_QUE_ITEMSIZE            sizeof(Network_AcksType)

typedef struct
{
  uint8_t  type;
  uint8_t  result;
  uint16_t packetId;
}Network_AcksType;

typedef struct
{
  cJSON *root;
  cJSON *params;
  cJSON *arrayitem;
  cJSON *identity;
  cJSON *property;
  cJSON *js_value;
}Network_JsonPointerType;

extern MQTTContext_t MQTT_Context;

extern char Network_Pub_topic[NETWORK_PUB_TOPIC_BUFFER_MAXLEN];
extern char Network_Sub_topic[NETWORK_SUB_TOPIC_BUFFER_MAXLEN];

extern char Network_Pub_payload[NETWORK_PUB_PAYLOAD_BUFFER_MAXLEN];
extern char Network_Sub_payload[NETWORK_SUB_PAYLOAD_BUFFER_MAXLEN];

extern char Network_Local_did[ROUTE_DID_BUFLEN];
extern char Network_Token[ROUTE_TOKEN_BUFLEN];

/* network transport layer */
extern const TransportInterface_t Network_TransportInterface;
extern uint32_t Network_GetTimestamp(void);
extern void Network_TransportLayerInit(void);

extern void Network_Init(void);
extern uint8_t Network_Connect(void);
extern void Network_PbulishMsg(Route_PayloadType *rtpl);
extern uint8_t Network_Subscribe(void);

#endif /* __netwrok_H */
